package com.ruoyi.collect.service.impl;

import com.ruoyi.collect.domain.TbCollect;
import com.ruoyi.collect.mapper.TbCollectMapper;
import com.ruoyi.collect.service.ITbCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 收藏Service业务层处理
 * 
 * @author 劳雅玲
 * @date 2024-03-26
 */
@Service
public class TbCollectServiceImpl implements ITbCollectService 
{
    @Autowired
    private TbCollectMapper tbCollectMapper;

    /**
     * 查询收藏
     * 
     * @param id 收藏主键
     * @return 收藏
     */
    @Override
    public TbCollect selectTbCollectById(Long id)
    {
        return tbCollectMapper.selectTbCollectById(id);
    }

    /**
     * 查询收藏列表
     * 
     * @param tbCollect 收藏
     * @return 收藏
     */
    @Override
    public List<TbCollect> selectTbCollectList(TbCollect tbCollect)
    {
        return tbCollectMapper.selectTbCollectList(tbCollect);
    }

    /**
     * 新增收藏
     * 
     * @param tbCollect 收藏
     * @return 结果
     */
    @Override
    public int insertTbCollect(TbCollect tbCollect)
    {
        return tbCollectMapper.insertTbCollect(tbCollect);
    }

    /**
     * 修改收藏
     * 
     * @param tbCollect 收藏
     * @return 结果
     */
    @Override
    public int updateTbCollect(TbCollect tbCollect)
    {
        return tbCollectMapper.updateTbCollect(tbCollect);
    }

    /**
     * 批量删除收藏
     * 
     * @param ids 需要删除的收藏主键
     * @return 结果
     */
    @Override
    public int deleteTbCollectByIds(Long[] ids)
    {
        return tbCollectMapper.deleteTbCollectByIds(ids);
    }

    /**
     * 删除收藏信息
     * 
     * @param id 收藏主键
     * @return 结果
     */
    @Override
    public int deleteTbCollectById(Long id)
    {
        return tbCollectMapper.deleteTbCollectById(id);
    }

    @Override
    public int del(TbCollect tbCollect) {
        if (Objects.isNull(tbCollect.getUserId()) || Objects.isNull(tbCollect.getPostId())){
            return -1;
        }
        tbCollectMapper.dellete(tbCollect);

        return 1;
    }
}
